package fr.univ.lr.icone.unit;

import static org.junit.Assert.*;

import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;

import org.jdom.JDOMException;
import org.junit.Test;

import fr.univ.lr.icone.gui.event.Event;
import fr.univ.lr.icone.gui.event.EventType;
import fr.univ.lr.icone.trace.Trace;

public class UnitTrace {

	@Test
	public void testRun() {

		try
		{
	//	this.ecritureXML();
		this.lectureXML();
		}
		catch(Exception e)
		{
			System.out.println(e);
		}
	}

	private void ecritureXML() throws InterruptedException {
		Trace trace = new Trace("unitTrace1.xml", true);

		EventType et = EventType.AGENT_CREATION;
		Event e = new Event(001, et, 1, 4, new Point(1, 1), null);
		trace.receiveEvent(e);
		Thread.sleep(20);
		e = new Event(002, et, 5, 4, new Point(2, 2), null);
		trace.receiveEvent(e);
		Thread.sleep(20);
		et = EventType.OPINION_CHANGED;
		e = new Event(002, et, 7, 4, new Point(2, 2), null);
		trace.receiveEvent(e);
		Thread.sleep(20);
		et = EventType.POSITION_CHANGED;
		e = new Event(002, et, 7, new Point(3, 2), new Point(2, 2));
		trace.receiveEvent(e);
		Thread.sleep(20);
		et = EventType.DISABLED_AGENT;
		e = new Event(002, et, 7, 4, new Point(3, 2), null);
		trace.receiveEvent(e);
		Thread.sleep(20);
		et = EventType.ENABLED_AGENT;
		e = new Event(002, et, 7, 4, new Point(3, 2), null);
		trace.receiveEvent(e);
		Thread.sleep(20);
		et = EventType.NONE;
		e = new Event(002, et);
		trace.receiveEvent(e);

		trace.start();

	}

	private void lectureXML() throws Exception {
		Trace trace = new Trace("unitTrace1.xml", false);

		try {
			HashMap<Event, Long> array = trace.getEventMap();

			

			System.out.println(array);
		

		} catch (InterruptedException e1) {

			e1.printStackTrace();
		} catch (JDOMException e1) {

			e1.printStackTrace();
		}

	}

}
